package com.the_last.mapper.convert;

import com.the_last.pojo.po.Venue;
import com.the_last.pojo.vo.VenueVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.text.SimpleDateFormat;
import java.util.Date;

@Mapper
public interface VenueConvert {
    VenueConvert INSTANCE = Mappers.getMapper(VenueConvert.class);
    
    @Mapping(target = "openTime", expression = "java(formatTime(venue.getOpenTime()))")
    @Mapping(target = "closeTime", expression = "java(formatTime(venue.getCloseTime()))")
    VenueVO toVO(Venue venue);
    
    default String formatTime(Date date) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        return sdf.format(date);
    }
    
}